#include "bc_weir_waterdepth.hpp"
#include "bc_weir_funcs.hpp"
#include "field.hpp"
#include "boundaryPatch.hpp"
#include "exceptions.hpp"
#include "formatHelpers.hpp"
#include "unifiedMathFunctions.hpp"

namespace hms {

#define CHEAD(RETURN_TYPE) \
template<typename MeshType> \
RETURN_TYPE Weir_waterdepth<MeshType>::

CHEAD() Weir_waterdepth(
	Field<MeshType>& d,
	const BoundaryPatch& p,
	const Field<MeshType>& v,
	scalar alpha
) :
	BaseType( Type::weir_waterdepth, d, p, d, v, alpha )
{}

CHEAD(void) update() const {
	Field<MeshType>& d { field() };
	const BoundaryPatch& patch { this->patch() };

	this->updateBuffers(true);

	const auto& dDom { d.domainValues(patch) };

	d.ghostValues(patch) = max( 0.5*dDom, 2*dEdge() - dDom );
}

#undef CHEAD

#define INSTANTIATE_FOR_ALL_MESHTYPES(MeshType) \
template class Weir_waterdepth<MeshType>;
#include "meshInstantiator.hpp"

} // namespace hms
